package com.zhongke.DKYCboot.controller;

import com.zhongke.DKYCboot.bean.BaseDriver;
import com.zhongke.DKYCboot.bean.ReceiveBaseDriver;
import com.zhongke.DKYCboot.service.BaseDriverService;
import com.zhongke.DKYCboot.util.FilePath;
import com.zhongke.DKYCboot.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@CrossOrigin
@RequestMapping("/base_driver")
public class BaseDriverController {
    @Autowired
    BaseDriverService baseDriverService;

    @Value("${imageServerUrl}")
    private String imageServerUrl;
    @Value("${imgBasePath}")
    private String imgBasePath;
    @Value("${driverPic}")
    private String driverPic;


    // 上传驾驶证图片，生成路径
    @RequestMapping(value = "/uploadDriverPic" ,method = RequestMethod.POST)
    public Msg uploadServiceOrder(MultipartFile file) throws IOException {
        String path = imgBasePath + driverPic;
        String filePath = FilePath.upload(file, path);
        String proMainImage = driverPic + filePath;
        return Msg.success(proMainImage);
    }
    // 新增司机
    @RequestMapping(value = "/insertBaseDriver" ,method = RequestMethod.POST)
    public Msg insertBaseDriver(BaseDriver baseDriver) {
        return baseDriverService.insertBaseDriver(baseDriver);
    }
    // 搜索司机
    @RequestMapping(value = "/selectBaseDriverList")
    public Msg selectBaseDriverList(ReceiveBaseDriver receiveBaseDriver,int pageNum,int pageSize) {
        return baseDriverService.selectBaseDriverList(receiveBaseDriver,pageNum, pageSize);
    }
    //批量删除司机信息
    @RequestMapping(value = "deleteBaseDriverMany" ,method = RequestMethod.POST)
    public Msg deleteBaseDriverMany(int [] ids,String updateBy){
        return baseDriverService.deleteBaseDriverMany(ids,updateBy);
    }
    //更新司机信息
    @RequestMapping(value = "updateBaseDriver" ,method = RequestMethod.POST)
    public  Msg updateBaseDriver(BaseDriver baseDriver){
        return baseDriverService.updateBaseDriver(baseDriver);
    }

}
